package com.flyou.ccnucenter.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.flyou.ccnucenter.R;
import com.flyou.ccnucenter.domain.News;
import com.flyou.ccnucenter.utils.SPUtils;

import java.util.List;

/**
 * ============================================================
 * 项目名称：flying
 * 包名称：com.flyou.flying.adapter
 * 文件名：SchoolNewsAdapter
 * 类描述：
 * 创建人：flyou
 * 邮箱：fangjaylong@gmail.com
 * 创建时间：2015/9/6 10:22
 * 修改备注：
 * 版本：@version  V1.0
 * ============================================================
 */
public class SchoolNewsAdapter extends BaseAdapter {
    private Context mContex;
    private List<News> mNewses;

    public SchoolNewsAdapter(Context context, List<News> newses) {
        this.mContex = context;
        this.mNewses = newses;
    }

    @Override
    public int getCount() {
        return mNewses.size();
    }

    @Override
    public Object getItem(int position) {
        return mNewses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final News news=mNewses.get(position);
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContex, R.layout.school_news_item, null);
            holder.newsTitle= (TextView) convertView.findViewById(R.id.news_title);

            convertView.setTag(holder);
        }
        else {
            holder= (ViewHolder) convertView.getTag();

        }
//        标注本地是否具有页面缓存，有的话就设置为灰色
        String newContent = (String) SPUtils.get(mContex,  news.getUrl(),"");
        holder.newsTitle.setTextColor(Color.BLACK);
        if (!TextUtils.isEmpty(newContent)){
            holder.newsTitle.setTextColor(Color.GRAY);
        }
        holder.newsTitle.setText(news.getTitle());

        return convertView;
    }

    class ViewHolder {
        TextView newsTitle;
    }
}
